package ep.io;

import java.io.FileNotFoundException;
import java.io.PrintStream;

import ep.model.Ant;
import ep.model.Board;

public class BoardAntPrinter {

	private static PrintStream out;

	private static int count = 1;

	private static PrintStream P1;

	static {
		try {
			BoardAntPrinter.out = new PrintStream("saida2.txt");
			BoardAntPrinter.P1 = new PrintStream("saida2.pbm");

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	public void printP1(Board board, Ant z){
		BoardAntPrinter.P1.println("P1");
		BoardAntPrinter.P1.println( board.getWidth() + " " + board.getHeight());

		for (int i = 0; i < board.getHeight(); i++) {
			for (int j = 0; j < board.getWidth(); j++) {
				if (z.getI() == i && z.getJ() == j) {
					BoardAntPrinter.P1.print("1");

				} else	if (board.getPositionState(i, j) == 1) {
					BoardAntPrinter.P1.print("1");
				} else {
					BoardAntPrinter.P1.print("0");
				}
			}
			BoardAntPrinter.out.println();
		}
	}

	public void print(Board board, Ant z) {
		//BoardAntPrinter.out.println();
		BoardAntPrinter.out.println();
		//BoardAntPrinter.out.print("Board " + BoardAntPrinter.count++);
		BoardAntPrinter.out.println();
		//BoardAntPrinter.out.println();

		for (int i = 0; i < board.getHeight(); i++) {
			for (int j = 0; j < board.getWidth(); j++) {
				if (z.getI() == i && z.getJ() == j) {
					BoardAntPrinter.out.print("A");
				} else	if (board.getPositionState(i, j) == 1) {
					BoardAntPrinter.out.print("1");
				} else {
					BoardAntPrinter.out.print("0");
				}
			}
			BoardAntPrinter.out.println();
		}
		printP1( board, z);
	}
}
